﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using xiaodingmarket_Domain.Interfaces.IRepository;
using xiaodingmarket_Domain.Models;
using xiaodingmarket_Infra_Data.Context;
using static xiaodingmarket_Domain.Models.EunmType;

namespace xiaodingmarket_Infra_Data.Repository
{
    public class OrderRepository : Repository<OrderCommodity>, IOrderRepository
    {
        public OrderRepository(MarketContext context)
            : base(context)
        {

        }
        /// <summary>
        /// 取出来某人的（商品or悬赏）的某个状态的一批订单信息，某参数为空就默认该参数范围是全部
        /// </summary>
        /// <param name="userid">创建订单人或者购买人</param>
        /// <param name="kind"></param>
        /// <param name="Condition"></param>
        /// <param name="who">0是创建订单的人，1是购买人</param>
        /// <returns></returns>
        public IQueryable<OrderCommodity> GetAll(Guid userid, int kind, int condition,int who)
        {
            if (who == 1)
            {
                return DbSet.Include(c => c.OrderDetail).Where(c => c.Buyer == userid&&c.Condition==(OrderCondition)condition);
            }
            else
            {
                return DbSet.Include(c => c.OrderDetail).Where(c => c.Seller == userid && c.Condition == (OrderCondition)condition);
            }
            
        }

        /// <summary>
        /// 根据特殊备注搜索订单
        /// </summary>
        /// <param name="remark"></param>
        /// <returns></returns>
        public IQueryable<OrderCommodity> GetAnyByRemark(string[] remark)
        {
            throw new NotImplementedException();
        }


    }
}
